package stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

public class StreamDemo {



    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();

        arrayList.add("a2123");
        arrayList.add("a1a3");
        arrayList.add("a1aa3");

        //arrayList.stream().filter(s -> s.startsWith("a")).filter(s -> s.length()>4).forEach(System.out::println);

        //MAP 体系
        Map<String, Integer> map = new HashMap<>();

        Stream<String> ke = map.keySet().stream();
        Stream<Integer> va = map.values().stream();
        Stream<Map.Entry<String, Integer>> stream = map.entrySet().stream();
        //数组 创建

        //Stream<String> heel = Stream.of("heel", "asd");

        //arrayList.stream().sorted().forEach(System.out::println);

//        arrayList.stream().sorted((String s1, String s2) -> {
//            return s2.length() - s1.length();
//        }).forEach(System.out::println);

        arrayList.stream().sorted((s1,s2) -> {
            int num = s1.length() - s2.length();
            int num1 = num == 0 ? s1.compareTo(s2) : num;
            return num1;
        }).forEach(System.out::println);

        System.out.println("------------");

        ArrayList<Integer> array = new ArrayList<>();
        array.add(12);
        array.add(2);
        array.add(122);
        array.add(123);
        array.add(122);

        // 将集合中的数字转化为string后输出

        // array.stream().map(integer -> String.valueOf(integer)).forEach(System.out::println);

//        array.stream().map(String::valueOf).forEach(System.out::println);
//
//
//        int sum = array.stream().mapToInt(i -> i).sum();
//        System.out.println(sum);




    }
}
